/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core.io;

import core.model.ClientInfor;
import core.model.UserInfor;
import java.util.Locale;
import org.apache.mina.core.session.IoSession;

/**
 *
 * @author Dung Pham
 */
public final class Session {

    /**
     * Session cua mina dung de trao doi du lieu cua socket.
     */
    private transient IoSession minaSession;
    private SessionAttribute sessionInfor;
    private ClientInfor clientInfor;
    private UserInfor userInfor;
    private Locale locale;

    public Session(IoSession iSession, SessionAttribute infor) {
        this.minaSession = iSession;
        this.sessionInfor = infor;
        this.minaSession.setAttribute(Attribute.SESSION_INFOR, infor);       
    }

    /**
     * Write data to network output stream.
     * @param data An IwinMessage format.
     */
    private void write(Message data) {
        if (data == null || minaSession == null) {
            return;
        }        
        minaSession.write(data);
    }

    /**
     * Write data to network output stream.
     * @param data An IwinMessage format.
     */
    public void sendMessage(Message data) {
        write(data);
    }
    
    /**
     * @return the minaSession
     */
    public IoSession getMinaSession() {
        return minaSession;
    }

    /**
     * @return the sessionInfor
     */
    public SessionAttribute getSessionInfor() {
        return sessionInfor;
    }

    /**
     * @return the clientInfor
     */
    public ClientInfor getClientInfor() {
        return clientInfor;
    }

    /**
     * @return the userInfor
     */
    public UserInfor getUserInfor() {
        return userInfor;
    }
    
}
